package com.newtype.meeting.client.mvc.frontend;

import java.util.List;

import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.mvc.AppEvent;
import com.extjs.gxt.ui.client.mvc.Controller;
import com.extjs.gxt.ui.client.mvc.View;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.newtype.meeting.client.AppEvents;
import com.newtype.meeting.client.model.Meeting;
import com.newtype.meeting.client.mvc.AppView;
import com.newtype.meeting.client.widget.frontend.StartMeetingListPanel;

public class StartMeetingListView extends View {
	private StartMeetingListPanel startMeetingListPanel;
	private LayoutContainer wrapper = Registry.get(AppView.CENTER_PANEL);

	@Override
	protected void initialize() {
		super.initialize();

		startMeetingListPanel = new StartMeetingListPanel();
	}

	public StartMeetingListView(Controller controller) {
		super(controller);
	}

	@Override
	protected void handleEvent(AppEvent event) {
		if (event.getType().equals(AppEvents.ViewStartMeetingList)) {
			onViewStartMeetingList(event);
		}
	}

	private void onViewStartMeetingList(AppEvent event) {
		wrapper.removeAll();
		ListStore<Meeting> startStore = startMeetingListPanel.getStartStore();
		startStore.removeAll();
		startStore.add(event.<List<Meeting>> getData("starts"));

		ListStore<Meeting> cancelStore = startMeetingListPanel.getCancelStore();
		cancelStore.removeAll();
		cancelStore.add(event.<List<Meeting>> getData("cancels"));

		wrapper.add(startMeetingListPanel);
		wrapper.layout();
	}
}
